Method, system, and computer program product for automatically mitigating vulnerabilities in source code

ABSTRACT

A method for automatically mitigating vulnerabilities in a source code of an application is provided in the present invention. The method includes the following steps. First, the source code is complied, and a path graph is built according to the compiled source code. The path graph includes a plurality of paths traversing from sources to sinks, and each of the paths includes a plurality of nodes. Then, at least one tainted path is identified by enabling a plurality of vulnerability rules. Each of the at least one tainted path corresponds to a vulnerability, and each of the at least one vulnerability corresponds to a sanitization method. Then, the at least one vulnerability is determined if it is mitigable. If the at least one vulnerability is mitigable, the at least one vulnerability is mitigated automatically. Furthermore, the method may be implemented as a system and a computer program product.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation-in-part application of and claims thepriority benefit of U.S. application Ser. No. 15/465,603, filed on Mar.22, 2017, now U.S. Pat. No. 10,044,747 issued Aug. 7, 2018. The priorU.S. application Ser. No. 15/465,603 is a continuation application ofand claims the priority benefit of U.S. application Ser. No. 14/845,281,filed on Sep. 4, 2015, now U.S. Pat. No. 9,639,703 issued May 2, 2017.The prior application Ser. No. 14/845,281 is a continuation applicationof and claims the priority benefit of U.S. application Ser. No.13/905,096, filed on May 29, 2013, now U.S. Pat. No. 9,158,922 issuedOct. 13, 2015. The entirety of each of the above-mentioned patentapplications is hereby incorporated by reference herein and made a partof this specification.

TECHNICAL FIELD

The present invention relates to software security vulnerabilities. Moreparticularly, the present invention relates to comprehensive techniquesfor automatically mitigating software security vulnerabilities in sourcecode.

BACKGROUND

Businesses rely more and more on the cloud to keep their applicationsrunning and data accessible. However, a high percentage of websites havevulnerabilities that may lead to the theft of data such as credit cardinformation and customer lists. Business needs application securitysolutions to avoid business interruptions and costly lawsuits. Thesoftware developers have historically focused on securityvulnerabilities and other serious functionality issues in the softwarethat may be exploited by hackers. Despite the efforts, the securityvulnerabilities remain as serious threats in the application level.

Various methods have been developed to identify security vulnerabilitiesin applications, such as black-box testing and static code analysis.Static code analysis is used by the software developers to analyzesoftware for problems and inconsistencies before actually compiling thesource code and executing programs built from the code for the software,and such technique is aimed at locating and describing areas of securityvulnerabilities in the source code. Most high-level optimizationsperformed by a modern compiler involve static analysis such as code pathanalysis, which is used to detect the propagation of an object andfurther validate the legality along a code execution path. Static codeanalysis is differentiated from dynamic analysis techniques by analyzingthe source code for dependencies without relying on dynamic events in amore complete view of every possible execution path rather than someaspects of a necessarily limited observed behavior.

Several existing static code analysis tools are capable of scanning thesource code by leveraging predefined security rules such that potentialvulnerabilities are detected and reported to the software developers.The vulnerability report may be accompanied by generic remediationcriteria, which proposes ways in which the software developers can amendthe source code so as to mitigate the reported vulnerabilities.Nonetheless, the software developers still need to implement andvalidate the problematic source code manually, which may belabor-intensive in consideration of a large amount of existingapplications. Due to lack of time or resources, many stakeholders areforced to deploy the applications even knowing they have potentialsecurity issues.

SUMMARY

The present invention provides a method, a system and a computer programproduct, which are capable of effectively mitigating vulnerabilities ina source code.

An exemplary embodiment of the present invention provides a method forautomatically mitigating vulnerabilities in a source code of anapplication. The method includes the following steps. First, the sourcecode is complied, and a path graph is built according to the compiledsource code. The path graph includes a plurality of paths traversingfrom sources to sinks, and each of the paths includes a plurality ofnodes. Then, at least one tainted path is identified by enabling aplurality of vulnerability rules. Each of the at least one tainted pathcorresponds to a vulnerability, and each of the at least onevulnerability corresponds to a sanitization method.

According to one of exemplary embodiments, the step of determining ifthe at least one vulnerability is mitigable is included as follows. Afirst forward node containing a tainted object is located as a targetnode along each of the at least one tainted path from the source to thesink.

According to one of exemplary embodiments, the step of determining ifthe at least one vulnerability is mitigable is included as follows. Afirst backward node containing the tainted object is located as thetarget node along each of the at least one tainted path from the sink tothe source.

According to one of exemplary embodiments, the step of determining ifthe at least one vulnerability is mitigable further includes thefollowing steps. The type of the at least one vulnerability isdetermined. If the at least one vulnerability is one of a structuredquery language (SQL) injection, an operating system (OS) commandinjection, a lightweight directory access protocol (LDAP) injection, anextensible markup language (XML) injection, or an XML path language(XPath) injection, the node containing the tainted object is located asthe target node along each of the at least one tainted path from thesource to the sink. If the at least one vulnerability is not any of theSQL injection, the OS command injection, the LDAP injection, the XMLinjection, or the XPath injection, the node containing the taintedobject is located as the target node along each of the at least onetainted path from the sink to the source. Then, an actualobject/variable is determined if it exists in the target node. If theactual object/variable exists, the at least one vulnerability isdetermined to be mitigatble. If the actual object/variable does notexist, a next node is set as the target node.

According to one of exemplary embodiments, the step of mitigating thedetermined at least one vulnerability automatically is included asfollows. An instant-fix call is applied at the tainted object on thetarget node.

According to one of exemplary embodiments, after the step of applyingthe instant-fix call at the tainted object on the target node, themethod further includes the following steps. A copy of amended sourcecode is created according to the instant-fix call. The copy of amendedsource code is checked if it is legal. If the copy of amended sourcecode is legal, the target node is written into a database. If the copyof amended source code is not legal, the next node is set as the targetnode.

According to one of exemplary embodiments, the step of determining ifthe at least one vulnerability is mitigable is included as follows. Atleast one other tainted path with the same target node is identified.The same target node is determined if it corresponds to differentvulnerabilities. If the same target node does not correspond todifferent vulnerabilities, the at least one other tainted path isremoved. If the same target node corresponds to differentvulnerabilities, a priority order of the vulnerabilities is evaluated.

According to one of exemplary embodiments, the step of mitigating thedetermined at least one vulnerability automatically is included asfollows. A plurality of instant-fix calls is applied at the taintedobject on the target node according to the priority order. A confidencescore corresponding to the instant-fix call is checked. The target nodeis written into a database.

According to one of exemplary embodiments, the method further includesthe following step. The confidence score is lowered if the taintedobject includes certain known functions.

According to one of exemplary embodiments, the method further includesthe following step. The at least one vulnerability is determined if itis one of the SQL injection, the OS command injection, the LDAPinjection, the XML injection, or the XPath injection. If the at leastone vulnerability is one of the SQL injection, the OS command injection,the LDAP injection, the XML injection, or the)(Path injection, theconfidence score is lowered if the tainted object includes certainstring constants.

According to one of exemplary embodiments, after the step of mitigatingthe determined at least one vulnerability automatically, the methodfurther includes the following steps. A copy of amended source code iscreated according to the instant-fix calls. The copy of amended sourcecode is compiled and determined if there exists any compiler error. Theactual tainted object on the mitigable node corresponding to each of thecompiler errors is located and the corresponding confidence score is setto zero.

An exemplary embodiment of the present invention provides a system forautomatically mitigating vulnerabilities in a source code of anapplication is provided in the present invention. The system includes amemory, a database, a processor. The processor is coupled to the memoryand the database, wherein the processor performs an operation forautomatically mitigating vulnerabilities in the source code of theapplication, wherein the operation includes the following steps. First,the source code is complied, and a path graph is built according to thecompiled source code. The path graph includes a plurality of pathstraversing from sources to sinks, and each of the paths includes aplurality of nodes. Then, at least one tainted path is identified byenabling a plurality of vulnerability rules. Each of the at least onetainted path corresponds to a vulnerability, and each of the at leastone vulnerability corresponds to a sanitization method.

According to one of exemplary embodiments, the processor locates a nodecontaining a tainted object as a target node along each of the at leastone tainted path from the source to the sink.

According to one of exemplary embodiments, the processor locates thenode containing the tainted object as the target node along each of theat least one tainted path from the sink to the source.

According to one of exemplary embodiments, the processor determines thetype of the at least one vulnerability. The processor locates a firstforward node containing the tainted object as the target node along eachof the at least one tainted path from the source to the sink if the atleast one vulnerability is one of the SQL injection, the OS commandinjection, the LDAP injection, the XML injection, or the XPathinjection. Alternatively, the processor locates a first backward nodecontaining the tainted object as the target node along each of the atleast one tainted path from the sink to the source if the at least onevulnerability is not any of the SQL injection, the OS command injection,the LDAP injection, the XML injection, or the XPath injection. Theprocessor further determines if an actual object/variable exists in thetarget node. The processor determines the at least one vulnerability ismitigable if the actual object/variable exists in the target node. Theprocessor sets a next node as the target node if the object/actualvariable does not exist in the target node.

According to one of exemplary embodiments, the processor applies aninstant-fix call at the tainted object on the target node.

According to one of exemplary embodiments, the processor creates a copyof amended source code according to the instant-fix call and checks ifthe copy of amended source code is legal. The processor writes thetarget node into the database if the copy of amended source code islegal; the processor sets the next node as the target node if the copyof amended source code is not legal.

According to one of exemplary embodiments, the processor identifies atleast one other tainted path with the same target node and determines ifthe same target node corresponds to different vulnerabilities. Theprocessor removes the at least one other tainted path if the same targetnode does not correspond to different vulnerabilities; the processorevaluates a priority order of the vulnerabilities if the same targetnode corresponds to different tainted objects.

According to one of exemplary embodiments, the processor applies aplurality of instant-fix calls at the tainted object on the target nodeaccording to the priority order, checks a confidence score correspondingto the instant-fix call, and writes the target node into the database.

According to one of exemplary embodiments, the processor further lowersthe confidence score if the tainted object includes certain knownfunctions.

According to one of exemplary embodiments, the processor furtherdetermines if the at least one vulnerability is one of the SQLinjection, the OS command injection, the LDAP injection, the XMLinjection, or the XPath injection. The processor may lower theconfidence score if the at least one vulnerability is one of the SQLinjection, the OS command injection, the LDAP injection, the XMLinjection, or the XPath injection and if the tainted object includescertain string constants.

According to one of exemplary embodiments, the processor further createsa copy of amended source code according to the instant-fix calls,compiles the copy of amended source code and determines if there existsany compiler error. The processor further locates the actual taintedobject on the mitigable node corresponding to each of the compilererrors and sets the corresponding confidence score to zero.

An exemplary embodiment of the present invention provides a computerprogram product stored in a computer readable storage medium forautomatically mitigating vulnerabilities in a source code of anapplication is provided in the present invention. The computer programincluding code for searching for at least one vulnerability within thesource code, determining if the at least one vulnerability is mitigable,and mitigating the determined at least one vulnerability automatically.

In order to make the aforementioned features and advantages of thepresent disclosure comprehensible, preferred embodiments accompaniedwith figures are described in detail below. It is to be understood thatboth the foregoing general description and the following detaileddescription are exemplary, and are intended to provide furtherexplanation of the disclosure as claimed.

It should be understood, however, that this summary may not contain allof the aspect and embodiments of the present disclosure and is thereforenot meant to be limiting or restrictive in any manner. Also the presentdisclosure would include improvements and modifications which areobvious to one skilled in the art.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings are included to provide further understanding,and are incorporated in and constitute a part of this specification. Thedrawings illustrate exemplary embodiments and, together with thedescription, serve to explain the principles of the disclosure.

FIG. 1 is a system for automatically mitigating vulnerabilities in asource code according to an exemplary embodiment of the presentinvention.

FIG. 2 is a flowchart illustrating a method for automatically mitigatingvulnerabilities in source code according to an embodiment of the presentinvention.

FIG. 3 is a flowchart illustrating an algorithm for automaticallymitigating vulnerabilities in source code according to an embodiment ofthe present invention.

FIG. 4 is a flowchart illustrating an algorithm for automaticallymitigating vulnerabilities in source code according to anotherembodiment of the present invention.

FIG. 5 is a flowchart illustrating an algorithm for automaticallymitigating vulnerabilities in source code according to anotherembodiment of the present invention.

FIG. 6A illustrates a schematic diagram of a first tainted path inaccordance with an embodiment of the present invention.

FIG. 6B illustrates a schematic diagram of a first tainted path and asecond tainted path in accordance with an embodiment of the presentinvention

DETAILED DESCRIPTION OF DISCLOSED EMBODIMENTS

Reference will now be made in detail to the present exemplaryembodiments of the disclosure, examples of which are illustrated in theaccompanying drawings. Wherever possible, the same reference numbers areused in the drawings and the description to refer to the same or likeparts.

FIG. 1 is a system for automatically mitigating vulnerabilities in asource code according to an exemplary embodiment of the presentinvention.

Referring to FIG. 1, a system 100 may be a personal computer, anembedded computer, a smart phone, a laptop computer, a tabular computeror other devices capable of performing the functions described in thepresent invention. The system 100 includes a processor 110, a memory120, a disk 130, and input/output (I/O) facilities 140. The processor110 is coupled to the memory 120, the disk 130, and the I/O facilities.The processor 110 may be a single chip or a multiple processor unit andmay include associated peripheral chips or functional blocks. Theprimary function of the processor 110 is to execute program instructionsby performing operations on data. The memory 120 may be a volatile ornon-volatile memory known to those skilled in the art including, forexample, a random access memory (RAM), a static random access memory(SRAM), or a dynamic random access memory (RAM). The disk 130 may be ahard disk drive (HDD) or a solid state drive (SSD) and is configured forstoring and retrieving files. For example, the disk 130 may includecomputer program products such as in the form of programming code,routines, or instruction blocks that provide a specific set or sets ofordered operations that control the functionality of the hardware anddirect its operation to perform some features or functionality of thesystem 100 once the instructions are loaded into the memory 120 andexecuted by the processor 110. The disk 130 may also include a database135, which may be implemented as any type of data storage structurecapable of providing for the retrieval and storage of a variety of datatypes. The I/O facilities 140 may include an interface for a monitor, akeyboard, a joystick, a mouse, a pointing device, a speech-basedinteraction device or the like. Additionally, in another exemplaryembodiment, the system 100 may further include other standard peripheralcomponents (not shown).

In one of exemplary embodiments, the system 100 may be viewed as aclient computer and connects to a server 160 via a network 170. Thenetwork 170 may be a computer network such as a local area network(LAN), wide area network (WAN), the Internet, or a cellular network. Theserver 160 may represent various forms of servers including, but notlimited to a web server, an application server, or a network server. Forexample, the server 160 may be an application server that executessoftware accessed by the system 100. A user may invoke applicationsavailable on the server 160 in a web browser running on the system 100.

The application software hosted by the server 160 may exhibit varioussecurity vulnerabilities. For example, the application software mayinclude vulnerable data and control flow patterns that enable hackers toforce the software to perform unintended actions. An example of suchproblem is called a structured query language (SQL) injection, whichoccurs when untrusted data makes its way through an application andeventually becomes a part of an SQL query. The hackers may firstidentify the flow of untrusted data from its entry point, referred to asa “source,” to a vulnerable Application Programming Interface (API),referred to as a “sink.” For example, the source of a securityvulnerability may be an injection of untrusted data in the parameter ofa HyperText Transfer Protocol (HTTP) request, and the sink of a securityvulnerability may be the process of data modification to manipulate thebehavior of the application, such as a HyperText Markup Language (HTML)page. The hackers may manipulate the input data to change the meaning ofthe SQL query and cause significant harm to the repository resourcessuch as a database system by simple assignments, method calls, orparameters passing. In other words, the hackers may inject an SQLstatement into an existing SQL statement, causing the execution of theSQL statement, which is not expected by the application, to manipulatethe database system in an unauthorized manner. Other knownvulnerabilities, such as operating system (OS) command injection,lightweight directory access protocol (LDAP) injection, extensiblemarkup language (XML) injection, XML path language (XPath) injection,cross-site scripting (XSS), weak cryptography, insecure redirect, errortriggering sensitive information leak, session hijacking, securitymisconfiguration, and weak authentication, are also often exploited byhackers and would be apparent to one of ordinary skill in the art.

FIG. 2 is a flowchart illustrating a method for automatically mitigatingvulnerabilities in source code according to an embodiment of the presentinvention.

In the present embodiment, source code of an application may be anysoftware code written in one or more programming languages includingcompiled languages such as C/C++, Java, Python, Pert, Ruby, PHP,Linux/UNIX shell script as well as interpreted languages such asassembly code, byte code, or instructions. Source code may be a fullyfunctional program or a subset of a program such as a command, function,method, class, library, or any code segment. Source code may alsoreference outside classes, objects, files, libraries or APIs.

Referring to FIG. 2 along with the components in FIG. 1, the method forautomatically mitigating vulnerabilities in source code including thefollowing steps. First, the processor 110 compiles the source code (StepS201) and builds a path graph according to the compiled source code(Step S203). Next, the processor 110 searches for at least onevulnerability within the source code (Step S205). To be more specific,after the processor 110 obtains the source code of an application, itmay compile the source code and builds a path graph according to thecompiled source code. Such path graph includes a plurality of pathstraversing from sources to sinks, and each of the paths includes aplurality of nodes. The path graph is used to determine those parts ofthe source code to which a particular value assigned to anobject/variable might propagate. The processor 110 then identifies atleast one tainted paths by enabling a plurality of vulnerability rules.The term “tainted” used herein refers to data that contains at leastsome data from an external source that is considered to be untrusted andpropagates through, for example, some object/variable assignments to adestination. Therefore, each of the at least one tainted pathcorresponds to a vulnerability, and each of the at least onevulnerability corresponds to a sanitization method. The at least onetainted paths may be identified by using an existing automated data flowanalysis tool to perform data flow analysis on the path graph. Forexample, theoretically, definite assignment analysis is one of data flowanalysis used by C/C++ compilers to conservatively ensure that anobject/variable is always assigned to before it is used. Java and C#programming language specifications require their compilers to report acompile-time error if the analysis fails. Also, the existing automateddata flow analysis tool may be some open source or free tools such asRIPS (a static source code analyzer for vulnerabilities in PHP webapplications), Google CodeSearchDiggity (a tool to identify SQLinjections, XSS, hard-coded passwords, etc), or RATS (a tool forscanning C/C++, Perl, PHP, Python source code for vulnerabilities suchas buffer overflows), and so on.

Next, the processor 110 determines if the at least one vulnerability ismitigable (Step S207). The at least one vulnerability may be associatedwith a node on a single tainted path or a node which is an intersectionof multiple tainted paths. Therefore, the processor 110 may need tolocate the exact position where the sanitization method may be placed sothat the determined at least one vulnerability may be mitigatedautomatically in a precise manner (Step S209).

FIG. 3 is a flowchart illustrating an algorithm for automaticallyvulnerabilities in source code according to an embodiment of the presentinvention. In the present embodiment, it is assumed that eachvulnerability is associated with a different mitigable node. In otherwords, each mitigable node is associated with a single tainted path.

Referring to FIG. 3 along with the components in FIG. 1, the processor110 loads paths and nodes by applying source code analysis techniquessuch as definite assignment analysis on source code (Step S301) andidentifies at least one tainted path by enabling a plurality ofvulnerability rules through a complete scan of the source code (StepS303). Similar to the previous embodiment, Step S301 and S303 may bedone by employing one of the existing automated data flow analysis toolsmentioned in the previous embodiment. For each vulnerability, theprocessor 110 needs to find a suitable sanitization method that may beapplied for each mitigable node, referred to as a “target node”hereinafter. Based on the type of the vulnerability, the processor 110may conduct a forward traversal or a backward traversal on the at leastone tainted path by following the tainted inputs of all computationsencountered throughout the at least one tainted path.

To be more specific, the processor 110 determines if the vulnerabilityis one of a SQL injection, a OS command injection, a LDAP injection, anXML injection, or an XPath injection (Step S305). The OS commandinjection is an escape string or format string attack that occurs whenunsanitized user input is passed to a system shell. The LDAP injectionis an attack used to exploit web based applications that construct LDAPstatements based on user input. The XML injection is a XML tag in asimple object access protocol (SOAP) message aiming at modifying the XMLstructure. Typical examples are modification of payment data andunauthorized administration login. The XPath injection is an attack whena website uses user-supplied information to construct an XPath query forXML data. Similar to the SQL injection, the hackers may exploit suchvulnerability with a command sequence appended to the appropriate formator escape string to execute arbitrary commands. When a softwareapplication fails to properly sanitize user input, it is possible tomodify commands or statements using a local proxy. A successfulinjection may result in the execution of arbitrary commands orrestricted operations such as elevating the privileges, grantingpermission to unauthorized queries and content modification. If thevulnerability is determined to be one of the SQL injection, the OScommand injection, the LDAP injection, the XML injection, or the XPathinjection, the processor 110 locates the first node containing a taintedobject (referred to as a first forward node) as the target node alongeach of the at least one tainted path from the source to the sink (StepS307). That is, among all the nodes containing the tainted inputsidentified by the processor 110, the first forward node is tainteddirectly from a pure external source (injection) but not inherited fromits parent node. On the other hand, if the vulnerability is determinedto be other than the SQL injection, the OS command injection, the LDAPinjection, the XML injection, or the XPath injection, the processor 110locates the first node containing the tainted object (referred to as afirst backward node) as the target node along each of the at least onetainted path from the sink to the source (Step S312).

After the target node is located, the processor 110 determines if theactual object/variable exists in the target node (Step S308 or StepS314). If the actual object/variable does not exist in the target node,the processor 110 sets a next node as the target node (Step S310 or StepS316) and repeats Step S308 or Step S314 respectively. That is, if thevulnerability is one of the SQL injection, the OS command injection, theLDAP injection, the XML injection, or the XPath injection, the processor110 may locate the second node containing the tainted object as a newtarget node from the source to the sink (Step S310) for ensuring thatthe tainted object in the target node is not inherited from its parentnode; otherwise, the processor 110 may locate the second node containingthe tainted object as a new target node from the sink to the source(Step S316).

If the actual object/variable exists in the target node, the processor110 determines that the current target node is mitigable and applies aninstant-fix call at the actual tainted object on the target node basedon the corresponding vulnerability rule (Step S317). The instant-fixcall is configured to amend the injection code based on the providedvulnerability rule by using an existing vulnerability analysis tool inconjunction with the knowledge that the database 135 has accumulatedover time in handling specific vulnerabilities in the past. In one ofexemplary embodiments, the processor 110 may assign a confidence score(e.g. 0-3) for each instant-fix call as a future reference. Moreover,the processor 110 creates a copy of amended source code according to theinstant-fix call.

Next, the processor 110 may compile the copy of amended source code andcheck if the copy of amended source code is compilable (Step S319). Ifthe copy of amended source code is compilable, the processor 110determines that the amendment is legal, writes the target node and thecorresponding amendment into the database 135 for references in thefuture (Step S321), and ends the algorithm. If the copy of amendedsource code is not compilable, the processor 110 determines that theamendment is illegal and returns to Step S310 or Step S316 for anotheridentification of a new target node until the mitigation is completed.

FIG. 4 is a flowchart illustrating an algorithm for automaticallymitigating vulnerabilities in source code according to anotherembodiment of the present invention. In the present embodiment, it isassumed that more than one vulnerabilities are associated with a samemitigable node. In other words, each mitigable node is an intersectionof multiple tainted paths.

Referring to FIG. 4, the processor 110 loads identified tainted pathsand target nodes by enabling a plurality of vulnerability rules (StepS401). It is noted that such process may be done by leveraging thealgorithm in FIG. 3, which will not be repeated hereinafter. For each ofthe tainted paths, the processor 110 may find the other intersectingtainted paths with the same target node as an intersection (Step S403).The processor 110 determines if the same target node corresponds todifferent vulnerability rules or tainted objects (Step S405). If thesame target node corresponds to the same vulnerability rule or the sametainted object, the processor 110 may then remove at least oneduplicated tainted path (Step S407). If the same target node correspondsto different vulnerability rules or different tainted objects, theprocessor may skip Step S407. For the same target node corresponds todifferent vulnerability rules or different tainted objects, theprocessor 110 may evaluate the priority order of the vulnerabilities formitigation by the vulnerability rules (Step S409), which may defineactual objects/variables on the target node and determine an optimalorder to mitigate the vulnerability accordingly. Similar to Step S317,the processor 110 then may apply multiple instant-fix calls at theactual tainted objects/variables on the target node based on thecorresponding vulnerability rule (Step S411).

Furthermore, the processor 110 may check the confidence score of each ofthe instant-fix calls (Step S413). In some embodiments, the processor110 may choose not to apply the instant-fix calls with low confidencescores. The processor 110 may also adjust the confidence score at thispoint. First, the processor 110 determines if the vulnerability is oneof the SQL injection, the OS command injection, the LDAP injection, theXML injection, or the)(Path injection (Step S415). If the vulnerabilityis one of the SQL injection, the OS command injection, the LDAPinjection, the XML injection, or the XPath injection, the processor 110checks if the injection contains certain string constants (Step S417).If the injection contains certain string constants, the processor 110may lower the confidence score of the corresponding instant-fix call(Step S419). If the vulnerability is not any one of the SQL injection,the OS command injection, the LDAP injection, the XML injection, or theXPath injection, the processor may skip Step S417 and directly proceedsto Step S421. In Step S421, the processor checks if the injectioncontains certain known functions. If the injection contains certainknown functions, the processor 110 may lower the confidence score of thecorresponding instant-fix call (Step S423) and save each of theinstant-fix call and its related information into the database 135 (StepS425). It is noted that, if the injection does not contain certain knownfunctions, the processor 110 may skip Step S423. Take the SQL injectionas an example. The certain string constants may be concatenated withexisting SQL commands, or the certain known functions may be meaningfulSQL commands. As long as injected SQL code is syntactically correct, theprocessor 110 may not easily detect programmatically. Therefore, theprocessor 110 may need to validate the resulting instant-fix calls witha more careful review. In other words, the resulting instant-fix callsmay be less reliable and receive lower confidence scores.

Next, the processor 110 may compile the copy of amended source code andcheck if the copy of amended source code is compilable (Step S427). Ifthe copy of amended source code is compilable, the processor 110determines that the amendment is legal and ends the algorithm. If thecopy of amended source code is not compilable, the processor 110 locatesthe instant-fix call corresponding to each of the compiler errors, whichmeans that the amendment is not reliable, sets the confidence score tozero (Step S429) and ends the algorithm. It is noted that, before theprocessor 110 applies the instant-fix call, it may first check thecorresponding confidence score and make an adjustment based on theconfidence score. In one of exemplary embodiments, such adjustment maybe authenticated by the user manually.

By leveraging the algorithms presenting in the embodiments of FIG. 3 andFIG. 4, the system 100 in the present invention may automaticallymitigate security issues in source code. In one of exemplaryembodiments, when a user attempts to visit a website, the processor 110of the system 100 may be initiated by one of the I/O facilities 140 suchas a mouse click from the user, and first goes through the source codeof the website. Then, the processor 110 finds the problems hackers maypossibly exploit and then rewrite the source code to fix the problems.The user may then either verify and apply the fixes individually, ordeploy the secured source code for immediate remediation.

FIG. 5 is a flowchart illustrating an algorithm for automaticallymitigating vulnerabilities in source code according to anotherembodiment of the present invention.

Referring to FIG. 5 along with the components in FIG. 1, the method forautomatically mitigating vulnerabilities in source code including thefollowing steps. First, the processor 110 builds a path graph accordingto the source code (Step S501) and identifies at least one tainted pathcorresponding to a vulnerability from the path graph (Step S503).Similar to the previous embodiments, the path graph includes pathstraversing from a sink to a source, and each of the paths include nodes.For simplicity purpose, the number of tainted paths would be describedin singular herein, and yet the other embodiments the number of taintedpaths may be in plural.

Next, the processor 110 locates a target node in the tainted path basedon an existence of a tainted object (Step S505). Assume that theidentified tainted path is defined as “a first tainted path” andincludes “first nodes”. The processor 110 may identify the first nodewith a maximum confidence score associated with an instant-fix call andset such node as the target node in the first tainted path.

In an embodiment, the processor 110 may apply the instant-fix call atthe tainted object on each of the first nodes of the first tainted pathand set a confidence score corresponding to each of the first nodes.Next, the processor 110 may set the first node with the maximumconfidence score as the target node in the first tainted path. In thecase where two or more first nodes having the same maximum confidencescore, the processor 110 may set the one that is the closest to the sinkas the target node in the first tainted path. For example, FIG. 6Aillustrates a schematic diagram of a first tainted path in accordancewith an embodiment of the present invention. The processor 110 mayperform traversal from a sink node 611 all the way to a source node 620.Assume that the range of confidence score is 0-3. Once the traversalcompletes, suppose that a node 615 has a maximum confident score (e.g.3) among all the nodes in the first tainted path. The processor 110would set the node 615 as a target node of the first tainted path.

In another embodiment, the processor 110 may apply the instant-fix callat the tainted object starting from the sink node. Assume that thecurrently processed node is defined as “a current node”. The processor110 may apply the instant-fix call at the current node and set aconfidence score corresponding to the current node. Next, the processor110 may determine whether the confidence score of the current node isequal to an upper bound value. If the determination is affirmative, theprocessor 110 would set the current node as the target node and stoptraversing. If the determination is negative, the processor 110 wouldset a next node as the current node, apply the instant-fix call at thenew current node, and set a confidence score corresponding to the newcurrent node in a similar fashion. As an example of FIG. 6A, theprocessor 110 may perform traversal from the sink node 611. When thetraversal reaches the node 615 and its confident score meets the upperbound (i.e. 3), the processor 110 may terminate the traversal and setthe node 615 as the target node of the first tainted path.

In the case where multiple tainted paths exist, for example, a secondtainted path having second nodes are identified, when the first taintedpath and the second tainted path share the same target node, theprocessor 110 would adjust the previously-set confidence score of thetarget node with respect to the first tainted path according to theconfidence score of the target node with respect to the second taintedpath. Once the confidence score of the target node with respect to thefirst tainted path has been changed, the processor 110 wouldre-determine the first node with the maximum confidence score as a newtarget node in the first tainted path.

For example, FIG. 6B illustrates a schematic diagram of a first taintedpath and a second tainted path in accordance with an embodiment of thepresent invention, where a node 635 is a target node of both taintedpaths. Assume that confident scores of the node 635 are 3 and 2 withrespect to the first tainted path and the second tainted path. Theprocessor 110 may lower the confident score of the node 635 with respectto the first tainted path by, for example, amending its value from 3 to2, or from 3 to 2.5 (an average of 3 and 2). The processor 110 mayre-evaluate the target node in the first tainted path based on theamended confidence score. For example, a node 640 with a confidencevalue of 3 is not originally considered as a target node since the node635 is closer to the sink, whereas the node 640 would be determined asthe new target node after the amendment on the confidence score of thenode 635 is made.

Referring back to FIG. 5, once the target node is identified, theprocessor 110 obtains design and contextual information associated withthe target node in the tainted path to accordingly select a sanitizationmethod (Step S507) and mitigate at least one vulnerability in the targetnode in the tainted path automatically based on the selectedsanitization method (Step S509). In detail, suppose that the taintedpaths include a target tainted path. The processor 110 may perform oneor more analyses on the target tainted path to obtain the design andcontextual information associated with the target node to accordinglyselect the sanitization method from a list of possible sanitizationmethods. The analyses may include data flow analysis, vector analysis,lexical analysis, and graph analysis. The design and contextualinformation may direct to a vulnerability rule, an attack vector,context of the target tainted path, and the possible sanitizationmethods may correspond to different types of security coding methods.

For better comprehension, Table 1 to Table 3 respectively illustratethree examples where original vulnerable codes and differentsanitization methods are provided.

Table 1 illustrates an example of SQL injections from web requests withand without malicious string replacement being in-place. In Scenario 1,since some potential malicious strings are able to be filtered out by afunction query=query.Replace (“′”, “ ”) in a data flow, a sanitizationmethod SqlEncodeLite may be applied. In Scenario 2, since no particularprevention function is applied, a normal sanitization method SqlEncode,a relatively stronger tool than SqlEncodeLite, may be applied.

TABLE 1 Example 1 (Malicious string replacement in-place) Vector = webrequest Rule = SQL Injection Scenario 1 Scenario 2 Original var query =Request[″query″]; var query = Request[″query″]; Vulnerable query =query.Replace(″″′, ″″); sqlCmd.ExecuteQuery(″SELECT * CodesqlCmd.ExecuteQuery(″SELECT * FROM [Table] WHERE [Keyword] = ″′ + FROM[Table] WHERE [Keyword] = ″′ + query + ″″′); query + ″″′); Fix Code varquery = Request[″query″]; var query = Request[“query”]; query =query.Replace(″″′, ″″); sqlCmd.ExecuteQuery(“SELECT *sqlCmd.ExecuteQuery(″SELECT * FROM [Table] WHERE [Keyword] = ‘” + FROM[Table] WHERE [Keyword] = ″′ + SqlEncode(query) + “’”);SqlEncodeLite(query) + ″″′);

Table 2 illustrates an example of SQL injections from web requests,where potentially malicious objects were injected into different partsof SQL queries. In Scenario 1, since a potentially malicious object(“name”) is used as a query value in the SQL statement, the source codewould be secured by passing the object along with the SQL statement as aparameter (also known as “parameterized query”) so as to prevent theuser input from being embedded in the statement. In Scenario 2, sincethe potentially malicious object (“department”) is used as a table namein the SQL statement, it would not be able to be passed along as aparameter but would require to be sanitized by using a sanitizationmethod before embedded in the statement.

TABLE 2 Example 2 (Parameterized Query) Vector = web request Rule = SQLInjection Scenario 1 Scenario 2 Original string name = txtName.Text;string department = Vulnerable MySqlCommand cmd = newtxtDepartment.Text; Code MySqlCommand(″select email from MySqlCommandcmd = new Employees where firstName = ″′ + MySqlCommand(″select emailfrom name + ″″′, connection); [″ + department + ″]″, connection); FixCode string name = txtName.Text; string department = MySqlCommand cmd =new txtDepartment.Text; MySqlCommand(″select email from MySqlCommand cmd= new Employees where firstName = MySqlCommand(″select email from [″ +@name″, connection); SqlEncode(department) + ″]″,cmd.Parameters.AddWithValue(″@ connection); name″, name);

Table 3 illustrates an example of missing encryption of sensitive datawith and without additional attributes. In Scenario 1, since thedetected data is confidential social security number (SSN) information,an additional nationality decryption restriction may be set in additionto applying an ordinary encryption. In Scenario 2, since no extremesensitive data is detected, an ordinary encryption approach may beapplied without any additional decryption restriction.

TABLE 3 Example 3 (Encryption of Sensitive Data) Vector = sensitive dataRule = missing encryption of sensitive data Scenario 1 Scenario 2Original var ssnTextBox = new var emailTextBox = new VulnerableSystem.Web.UI.WebControls.TextBox( ); System.Windows.Controls.TextBox(); Code var ssn = ssnTextBox.Text; var email = emailTextBox.Text;db.Persons.Find(person).Ssn = ssn; db.Persons.Find(person). Email =email; Fix Code var ssnTextBox = new var emailTextBox = newSystem.Web.UI.WebControls.TextBox( ); System.Windows.Controls.TextBox(); var ssn = ssnTextBox.Text; var email = emailTextBox.Text;AesCryptoProvider AesCryptoProvider aesCryptoProvider =aesCryptoProvider = new new AesCryptoProvider(key, iv,AesCryptoProvider(key, iv, salt); salt); var encryptedSsn = varencryptedEmail = aesCryptoProvider.Encrypt(ssn);aesCryptoProvider.Encrypt(email); db.Persons.Find(person).Ssn = newdb.Persons.Find(person). Email = new Ssn(encryptedSsn) { Source =Email(email); Source.Web, Nationality = Country.US };

As a side note, in some implementations, the processor 110 may furtherselect the sanitization method from possible sanitization methodsaccording to user settings based upon the actual needs. For example, theuser may wish to protect email information as sensitive information. Anadditional restriction (e.g. IP location) may be set and specifiedbesides an ordinary encryption. Moreover, a priority order forsanitization may be preset by the user based on vulnerability rule,attack vector, context as well. Therefore, when multiple tainted pathsexist in the path graph, the processor 110 may mitigate thevulnerability in the target node in each tainted path sequentially basedon the priority order.

In one of exemplary embodiments, computer program products including aplurality of program instructions stored in a tangible computer mediumimplementing the functionality or method of this invention will commonlybe non-volatile, hard-coded type media distributed to users on adistribution medium, such as floppy disks, read only memories (ROMs),CD-ROMs, and DVD-ROMs, or erasable, electrically programmable read onlymemories (EEPROMs), recordable type media such as floppy disks, harddisk drives, CD-R/RWs, DVD-RAMs, DVD-R/RWs, DVD+R/RWs, flash drives, andother newer types of memories, and transmission type media such asdigital and analog communication links, or other computer-readablemedium. The term “computer-readable medium” encompasses distributionmedia, intermediate storage media, execution memory of a computer, andany other medium or device capable of storing computer programinstructions implementing the functionality or methods of embodiments ofthe present invention for later reading by a computer system. Thecomputer program will often be copied from the computer-readable mediumto a hard disk or a similar intermediate storage medium. When theprograms are to be run, they will be loaded either from theirdistribution medium or their intermediate storage medium into theexecution memory of the computer, configuring the computer to act inaccordance with the algorithm or method of this invention. All suchoperations are well known to those skilled in the art of computersystems.

In summary, by leveraging static code analysis and data flow graphs, thepresent invention provides a method, a system, and a computer programproduct for automatically mitigating vulnerabilities in a source code.By going through the source code of applications, the vulnerabilitiesthat hackers may exploit are able to be found, and then the source codeare re-written to mitigate the vulnerabilities. The users may theneither verify and apply the amendment individually or deploy the securedsource code for immediate remediation.

It will be apparent to those skilled in the art that variousmodifications and variations can be made to the structure of thedisclosed embodiments without departing from the scope or spirit of thedisclosure. In view of the foregoing, it is intended that the disclosurecover modifications and variations of this disclosure provided they fallwithin the scope of the following claims and their equivalents.

What is claimed is:
 1. A method for automatically mitigating vulnerabilities in a source code of an application via static analysis comprising: building a path graph according to the source code, wherein the path graph comprises a plurality of paths traversing from sinks to sources, and wherein each of the paths comprises a plurality of nodes; identifying at least one tainted path from the path graph, wherein each of the at least one tainted path corresponds to a vulnerability, and wherein the at least one tainted path comprises a first tainted path having a plurality of first nodes; locating a target node in each of the at least one tainted path based on an existence of a tainted object comprising: applying an instant-fix call at the tainted object on each of the first nodes of the first tainted path and setting a confidence score corresponding to each of the first nodes; identifying the first node with a maximum confidence score associated with the instant-fix call; and setting the first node with the maximum confidence score as the target node in the first tainted path; obtaining design and contextual information associated with the target node in each of the at least one tainted path to accordingly select a sanitization method; and mitigating at least one vulnerability in the target node in each of the at least one tainted path automatically based on the selected sanitization method.
 2. The method of claim 1, wherein the step of setting the first node with the maximum confidence score as the target node in the first tainted path comprises: setting the first node with the maximum confidence score and closest to the sink as the target node in the first tainted path.
 3. The method of claim 1, wherein the step of identifying the first node with the maximum confidence score associated with the instant-fix call comprises: applying the instant-fix call at the tainted object on a current node from the sink of the first tainted path and setting a confidence score corresponding to the current node; determining whether the confidence score of the current node is equal to an upper bound value; in response to the confidence score of the current node being determined to be equal to the upper bound value, setting the current node as the target node; and in response to the confidence score of the current node being determined to be not equal to the upper bound value, setting a next node as the current node.
 4. The method according to claim 1, wherein the at least one tainted path further comprises a second tainted path having a plurality of second nodes, wherein the first tainted path and the second tainted path have the same target node, and wherein the method further comprises: changing the confidence score of the target node in the first tainted path according to the confidence score of the target node in the second tainted path; and setting the first node with the maximum confidence score as a new target node in the first tainted path.
 5. The method according to claim 1, wherein the at least one tainted path further comprises a target tainted path, and wherein the step of obtaining the design and contextual information associated with the target node in each of the at least one tainted path to accordingly select the sanitization method comprises: performing at least one analysis on the target tainted path to obtain the design and contextual information associated with the target node; and selecting the sanitization method from a plurality of possible sanitization methods according to the design and contextual information associated with the target node.
 6. The method according to claim 5, wherein the at least one analysis comprises at least one of data flow analysis, vector analysis, lexical analysis, and graph analysis.
 7. The method according to claim 5, wherein the design and contextual information comprises a vulnerability rule of the target tainted path.
 8. The method according to claim 5, wherein the design and contextual information comprises an attack vector of the target tainted path.
 9. The method according to claim 5, wherein the design and contextual information comprises context of the target tainted path.
 10. The method according to claim 5, wherein the possible sanitization methods correspond to different types of security coding methods.
 11. The method according to claim 5, wherein the step of selecting the sanitization method from the possible sanitization methods according to the design and contextual information associated with the target node further comprises: selecting the sanitization method from the possible sanitization methods according to the design and contextual information associated with the target node and user settings.
 12. The method according to claim 1, wherein when there exists multiple tainted paths in the path graph, the step of mitigating the at least one vulnerability in the target node in each of the at least one tainted path automatically based on the selected sanitization method comprises: obtaining a preset priority order for sanitization; and mitigating the at least one vulnerability in the target node in each of the tainted paths in sequence automatically based on the corresponding selected sanitization method by referencing the preset priority order for sanitization.
 13. A system for automatically mitigating vulnerabilities in a source code of an application comprising: a memory; a processor coupled to the memory, wherein the processor performs an operation for automatically mitigating vulnerabilities in the source code of the application, the operation comprising: building a path graph according to the source code, wherein the path graph comprises a plurality of paths traversing from sinks to sources, and wherein each of the paths comprises a plurality of nodes; identifying at least one tainted path from the path graph, wherein each of the at least one tainted path corresponds to a vulnerability, and wherein the at least one tainted path comprises a first tainted path having a plurality of first nodes; locating a target node in each of the at least one tainted path based on an existence of a tainted object comprising: applying an instant-fix call at the tainted object on each of the first nodes of the first tainted path and setting a confidence score corresponding to each of the first nodes; identifying the first node with a maximum confidence score associated with the instant-fix call; and setting the first node with the maximum confidence score as the target node in the first tainted path; obtaining design and contextual information associated with the target node in each of the at least one tainted path to accordingly select a sanitization method; and mitigating at least one vulnerability in the target node in each of the at least one tainted path automatically based on the selected sanitization method.
 14. A non-transitory computer-readable medium comprising a plurality of program instructions, which when executed by a computer system, cause the computer system to execute steps of: building a path graph according to the source code, wherein the path graph comprises a plurality of paths traversing from sinks to sources, and wherein each of the paths comprises a plurality of nodes; identifying at least one tainted path from the path graph, wherein each of the at least one tainted path corresponds to a vulnerability, and wherein the at least one tainted path comprises a first tainted path having a plurality of first nodes; locating a target node in each of the at least one tainted path based on an existence of a tainted object comprising: applying an instant-fix call at the tainted object on each of the first nodes of the first tainted path and setting a confidence score corresponding to each of the first nodes; identifying the first node with a maximum confidence score associated with the instant-fix call; and setting the first node with the maximum confidence score as the target node in the first tainted path; obtaining design and contextual information associated with the target node in each of the at least one tainted path to accordingly select a sanitization method; and mitigating at least one vulnerability in the target node in each of the at least one tainted path automatically based on the selected sanitization method. 